//
//  ViewController.m
//  TestBlock
//
//  Created by apple on 15/12/3.
//  Copyright © 2015年 apple. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    [self initName:@"Herry" initAge:(NSInteger*)123];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
- (void)initName:(NSString*)name initAge:(NSInteger*) age{
    static int globle = 1;
    void(^myBlock)(NSString* name) = ^(NSString* name){
        _name = name;
        globle = 2;
    };
    myBlock(@"Daneil");
    _name = @"Yaboo";
    NSLog(@"%@,%zi,%@",_name,globle,myBlock);
    //--------------------------------------------------------------------------------------------
    __block int number = 10;

    int(^add)(int) = ^(int b){
        return number + b;
    };
    number = 5;
    NSLog(@"%zi,%@",add(5),add);
    //--------------------------------------------------------------------------------------------
    int a = 100;
    void (^block2)(void) = ^{
        printf("%d\n", a);
    };
    block2();
    NSLog(@"%@,@%p",block2,&a);
    //--------------------------------------------------------------------------------------------
    
    void (^global)(void) = ^{
        number = 200;
        printf("Hello, World!\n");
    };
    NSLog(@"%@",global);
}
@end
